package com.sc.nft.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.dto.UserRecommendDTO;
import com.sc.nft.entity.UserInfo;
import com.sc.nft.entity.dto.EarningsListDTO;
import com.sc.nft.entity.dto.PromotionRewardsDTO;
import com.sc.nft.entity.dto.SpecialRewardDTO;
import com.sc.nft.entity.dto.UserManageDaoDTO;
import com.sc.nft.entity.vo.*;
import jnr.ffi.annotations.In;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * (sc_user_info)数据Mapper
 *
 * @author Sun
 * @description 由 Mybatisplus Code Generator 创建
 * @since 2022-05-29 10:36:55
 */
@Mapper
public interface UserInfoMapper extends BaseMapper<UserInfo> {

    List<HashMap> findPositionRanking();

    HashMap findPositionRankingById(@Param("id") Long id);

    List<HashMap> findInviteRanking();

    HashMap findInviteRankingById(@Param("id") Long id);

    List<UserInfo> getTeamOwnerList(@Param("recommendUserId") String recommendUserId);

    Page<SimpleUserVO> simpleUserList(@Param("userTel") String userTel, Page page);

    Page<UserManageVO> pageUserInfo(@Param("userUuid") String userUuid, @Param("nickName") String nickName, @Param("userTel") String userTel, @Param("address") String address, Page page);

    List<CollectionByUserVO> collectionByUser(@Param("userId") Long userId, @Param("firstTitle") String firstTitle);

    List<CollectionByUserDetailVO> collectionByUserDetail(@Param("userId") Long userId, @Param("collectionId") Long collectionId);

    Page<UserManageDaoVO> mateDaoUserList(Page page, UserManageDaoDTO userManageDaoDTO);

    List<UserWithCollectionSimpleVO> userWithCollectionExport(Integer marketType);

    /**
     * 马特DAO-用户列表,某个用户详情
     *
     * @param recommendUserIdList
     * @return
     */
    UserMangeDaoUserInfoVO userMangeDaoUserInfo(String userTel, String recommendUserIdList);

    /**
     * 马特DAO-推广奖励列表
     *
     * @param page
     * @param promotionRewardsDTO
     * @return
     */
    Page<PromotionRewardsVO> promotionRewards(Page page, @Param("promotionRewardsDTO") PromotionRewardsDTO promotionRewardsDTO);

    /**
     * 马特DAO-用户信息,直推列表
     *
     * @param page   分页对象
     * @param userId 用户id
     * @return
     */
    Page<MaTeUserMangeDaoGeneralEarningsDirectlyListVO> mateUserMangeDaoGeneralEarningsDirectlyList(Page page, Long userId);

    /**
     * 马特DAO-用户信息,间推列表
     *
     * @param page   分页对象
     * @param userId 用户id
     * @return
     */
    Page<MaTeUserMangeDaoGeneralEarningsIndirectListVO> maTeUserMangeDaoGeneralEarningsIndirectList(Page page, Long userId);

    /**
     * 用户收益列表
     *
     * @param page
     * @param earningsListDTO
     * @return
     */
    Page<UserInfoEarningsVO> userInfoEarningsList(Page page, EarningsListDTO earningsListDTO);

    /**
     * 特殊奖励
     *
     * @param specialRewardDTO
     * @return
     */
    Page<SpecialRewardVO> specialReward(Page page, @Param("specialRewardDTO") SpecialRewardDTO specialRewardDTO);

    /**
     * 获取一级市场的交易总额
     *
     * @param recommendId
     * @return
     */
    BigDecimal getSumHoldTokenByRecommendId(@Param("recommendId") Long recommendId);

    /**
     * 获取二级市场的交易总额
     *
     * @param recommendId
     * @return
     */
    BigDecimal getSumSecondaryHoldTokenByRecommendId(@Param("recommendId") Long recommendId);


    /**
     * 修改用户等级
     *
     * @param level
     * @param levelName
     * @param id
     * @return
     */
    Boolean updateUserLevel(@Param("level") int level, @Param("levelName") String levelName, @Param("id") Long id);

    /**
     * 获取城市服务中心的用户列表
     *
     * @return
     */
    List<UserInfo> getUserCityServerCentre();

    /**
     * 根据手机号获取用户基本信息
     *
     * @param userTel
     * @return
     */
    UserTelGetUserInfoVO userTelGetUserInfo(@Param("userTel") String userTel);

    /**
     * 获取总领主数量
     *
     * @return
     */
    Integer getPartnerCount();

    /**
     * 获取数量 根据等级
     *
     * @param level
     * @return
     */
    Integer getCountByLevel(@Param("level") Integer level);

    /**
     * 获取全部数量
     *
     * @return
     */
    Integer getCount();

    /**
     * 获取用户实名并且没有加入官方群的数据,数据根据分页数据来.
     *
     * @return
     */
    List<UserInfo> getUserIsSmAndIsOfficialLimit(Page page, @Param("list") List list);

    Integer getYesterDayCount();

    Integer getYesterDayCountByDay(@Param("day") String day);

    Integer getByListUserIdCountValid(@Param("userId") Long userId, @Param("urbanServiceCenter") Boolean urbanServiceCenter);

    List<UserWithCollectionSimpleVO> getDestroyCount(@Param("collectionIdList") List<Long> collectionIdList);

    Integer getOneDestroyCount(@Param("collectionId") Long collectionId);

    List<UserWithCollectionSimpleVO> countCollection(@Param("collectionIdList") List<Long> collectionIdList);

    List<UserWithCollectionSimpleVO> marketAccountCollection(@Param("collectionIdList") List<Long> collectionIdList, @Param("userIdList") List<Long> userIdList);

    List<UserWithCollectionSimpleVO> userCount(@Param("collectionIdList") List<Long> collectionIdList);

    List<UserWithCollectionSimpleVO> marketAccountCount(@Param("collectionIdList") List<Long> collectionIdList, @Param("userIdList") List<Long> userIdList);

    /**
     * 根据用户手机号查询用户碎片信息
     *
     * @param userTelList
     * @return
     */
    List<BatchEnterIntegrationShowListVO> userTelByAssets(@Param("list") List<String> userTelList);

    /**
     * 获取城市服务中心用户下有效的用户数量（排除品牌方DAO用户下的）
     *
     * @param serviceCenterUserId
     * @param daoUserId
     * @return
     */
    Integer getCountValidByUserId(@Param("serviceCenterUserId") Long serviceCenterUserId, @Param("daoUserId") Long daoUserId);

    /**
     * 获取品牌拉新人数
     *
     * @param daoUserId
     * @param daoOnlineTime dao上线时间
     * @return
     */
    Integer getDaoNewUserNum(@Param("daoUserId") Long daoUserId, @Param("daoOnlineTime") Date daoOnlineTime);

    /**
     * 获取服务中心拉新人数
     *
     * @param serviceCenterUserId
     * @param daoUserId
     * @param daoOnlineTime  dao上线时间
     * @return
     */
    Integer getServiceCenterNewUserNum(@Param("serviceCenterUserId") Long serviceCenterUserId, @Param("daoUserId") Long daoUserId, @Param("daoOnlineTime") Date daoOnlineTime);

    @Select("select * from sc_user_info where id not in (select user_id from sc_user_wallet)")
    List<UserInfo> getNotInitUserList();


    Integer insertUser(UserInfo userInfo);

    List<UserCollectionConsensusExcelParsingListVO> userTelByConsensus(@Param("userTelList") List<String> userTelList);

    @Select("select count(*) from sc_user_info where id in (select relevance_id from sc_user_relevance where user_id=#{userId})")
    Integer getUnderTeamCount(@Param("userId")Long userId);

    @Select("select count(*) from sc_user_info where is_sm=1 and id in (select relevance_id from sc_user_relevance where user_id=#{userId})")
    Integer getUnderRealNameCount(@Param("userId")Long userId);

    @Select("select date_format(create_time,'%Y-%m-%d') as create_date ,count(*)  as register_count from sc_user_info where  id in (select relevance_id from sc_user_relevance where user_id=#{userId} ) and  create_time>#{startTime} group by date_format(create_time,'%Y-%m-%d')")
    List<DaoLastMonthUserInfoVO> getLastMonthUserInfo(@Param("userId") Long userId,@Param("startTime")Date startTime);

    List<Long> listRecommendByUserId(@Param("userId") Long userId);


    List<UserRecommendDTO> listRecommendByUserIdList(@Param("userIdList") List<Long> userIdList);
}
